package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTradeMarkController {

    @Autowired
    private ManageService manageService;

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //查询    /admin/product/baseTrademark/{page}/{limit}
    @GetMapping("{page}/{limit}")
    public Result getTradeMarkList(@PathVariable Long page,
                                   @PathVariable Long limit) {
        //创建对象
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> iPage = this.baseTrademarkService.getTradeMarkList(baseTrademarkPage);

        //返回数据
        return Result.ok(iPage);
    }

    //删除    /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("remove/{id}")
    public Result removeBaseTrademark(@PathVariable Long id) {
        //调用服务层
       // this.baseTrademarkService.deleteById(id);
        this.baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //保存  /admin/product/baseTrademark/save
    @PostMapping("save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        this.baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //访问调用    /admin/product/baseTrademark/get/{id}
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        //调用访问
        BaseTrademark baseTrademark = this.baseTrademarkService.getById(id);
        //返回
        return Result.ok(baseTrademark);
    }


    //   /admin/product/baseTrademark/update
    @PutMapping("update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        //调用方法
        this.baseTrademarkService.updateById(baseTrademark);
        return  Result.ok();
    }

}
